package com.kafka.demoka.controller;


import com.alibaba.fastjson.JSON;
import com.kafka.demoka.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class kafkaController {

    @Autowired
    private KafkaTemplate kafkaTemplate;


    @RequestMapping("/send")
    public void send(){
        User user= new User();
        user.setName("good");
        user.setAge(14);
        kafkaTemplate.send("user", JSON.toJSONString(user));
    }
}
